#include <stdio.h>

void quick_sort(int s[], int l, int r)
{
    int i, j, k;
    if(l<r)
    {
        i = l;
        j = r;
        x = s[i];
        while(i<j)
        {
            while(i<j && s[j] > x)
                j--;
            if(i<j)
                s[i++] = s[j];

            while(i<j&& s[i]<x)
                i++;
            if(i<j)
                s[j--] = s[i]
        }
        s[i] = x;//重要的一步， 将最后一个空位置补上
        quick_sort(s, l, i-1);
        quick_sort(s, i+1, r);
    }
}

int main(int argc, char * argv[])
{
    int a[] = {4,3,6,9,7,1,2};
    int l = 0;
    int r = 6;
    quick_sort(a, l, r);
    for(int i = 0;i<=r;i++)
        printf("%4d", a[i]);

        return 0;
}